package com.voyage.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.voyage.common.constant.PageMO;
import com.voyage.system.entity.BorrowDO;
import com.voyage.system.mapper.BorrowRepository;
import com.voyage.system.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class BorrowServiceImpl implements BorrowService {

    private final BorrowRepository borrowRepository;

    @Autowired
    public BorrowServiceImpl(BorrowRepository borrowRepository) {
        this.borrowRepository = borrowRepository;
    }


    @Override
    public void insert(BorrowDO borrowDO) {
        borrowRepository.insert(borrowDO);
    }

    @Override
    public List<BorrowDO> list(QueryWrapper<BorrowDO> queryWrapper) {
        return borrowRepository.selectList(queryWrapper);
    }

    @Override
    public void update(BorrowDO borrowDO) {
        borrowRepository.updateById(borrowDO);
    }

    @Override
    public void delete(Long id) {
        borrowRepository.deleteById(id);
    }

    @Override
    public IPage<BorrowDO> page(PageMO pageMO) {
        IPage<BorrowDO> page = new Page<>(pageMO.getCurrent(), pageMO.getSize());
        QueryWrapper<BorrowDO> queryWrapper = new QueryWrapper<>();
        return borrowRepository.selectPage(page, queryWrapper);
    }
}
